<template>
    <div class="yemian">
        <div class="dingbu">
        <div class="biaoti">
          <img src="../../assets/image/纸飞机.png" class="tubiao">
          <span class="wz">NBM在线考试系统</span>
        </div>
        <XSCD />
        <div class="touxiang">
          <img src="../../assets/image/头型.png" style="height: 50px; width: 50px;">
          <UserInfo />
        </div>
      </div>
      
      <!-- 优化后的轮播图部分 -->
      <div class="LBT">
        <el-carousel 
          :interval="3000" 
          height="170px" 
          trigger="click" 
          arrow="never"
          indicator-position="outside"
          autoplay>
          <el-carousel-item v-for="(image, index) in images" :key="index">
            <img :src="image" class="carousel-image" />
          </el-carousel-item>
        </el-carousel>
      </div>

    <!-- 主内容区 -->
    <div class="exam-main">
      <!-- 左侧考试须知 -->
      <div class="exam-notice">
        <div class="notice-title">
          <el-icon><Notebook /></el-icon>
          <span>考试须知</span>
        </div>
        <div class="notice-content">
          <p>1. 考试须遵守纪律，诚信答题</p>
          <p>2. 禁止抄袭作弊</p>
          <p>3. 请确保网络连接稳定</p>
          <p>4. 考试期间不得切换浏览器标签</p>
          <p>5. 考试时间结束系统将自动提交</p>
        </div>
      </div>

      <!-- 右侧考试选择区 -->
      <div class="exam-selection">
        <div class="selection-header">
          <h2>请选择考试</h2>
          <el-button type="text" @click="viewExamRecords">
            <el-icon><Document /></el-icon>
            查看考试记录
          </el-button>
        </div>

        <!-- 考试列表 -->
        <div class="exam-list">
          <div class="exam-item" v-for="(exam, index) in exams" :key="index">
            <div class="exam-info">
              <h3>{{ exam.name }}</h3>
              <div class="exam-meta">
                <span class="exam-date">{{ exam.date }}</span>
                <span class="exam-subject">科目：{{ exam.subject }}</span>
                <span class="exam-duration">考试时间：{{ exam.duration }}分钟</span>
              </div>
            </div>
            <el-button 
              type="primary" 
              @click="startExam(exam)"
              :disabled="exam.status !== 'available'"
            >
              开始考试
            </el-button>
          </div>
        </div>
      </div>
    </div>

    </div>
</template>

<script setup>
  import { useRouter } from 'vue-router' 
  import XSCD from '../../components/XSCD.vue';
  import UserInfo from '../../components/UserInfo.vue';
  import { ref, computed } from 'vue';
  const router = useRouter()
  
  // 使用require确保图片正确加载
  const images = ref([
    new URL('../../assets/image/lb1.jpg', import.meta.url).href,
    new URL('../../assets/image/4.png', import.meta.url).href,
    new URL('../../assets/image/纸飞机.png', import.meta.url).href,
  ]);

  const exams = ref([
  {
    id: 'exam001',
    name: '2024一年级期末考试',
    date: '2024-1-1',
    subject: '语文',
    duration: 150,
    status: 'available'
  },
  {
    id: 'exam002',
    name: '2024一年级期末考试',
    date: '2024-1-1',
    subject: '数学',
    duration: 120,
    status: 'available'
  },
  {
    id: 'exam003',
    name: '2024一年级期末考试',
    date: '2024-1-1',
    subject: '英语',
    duration: 90,
    status: 'completed'
  }
])

// 查看考试记录
const viewExamRecords = () => {
  router.push('/exam-records')
}

// 开始考试
const startExam = (exam) => {
  router.push({
    path: '/exam-taking',
    query: { examId: exam.id }
  })
}
</script>

<style  scoped>
.yemian {
  width: 100%;
  min-height: 100vh;
  padding: 0 20px;
  box-sizing: border-box;
}

.dingbu {
  width: 100%;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e0e0e0;

  box-sizing: border-box;
}

.biaoti {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tubiao {
  height: 40px;
  width: 40px;
}

.wz {
  color: #333;
  font-size: 24px;
  font-weight: bold;
}

.touxiang {
  display: flex;
  align-items: center;
  gap: 10px;
}

.LBT {
  width: 100%;
  height: 170px;
  margin: 20px 0;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}




.exam-main {
  display: flex;
  max-width: 1200px;
  margin: 20px auto;
  gap: 20px;
}

.exam-notice {
  flex: 0 0 300px;
  background-color: #FFF8E6;
  border-left: 5px solid #FFC107;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.notice-title {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.notice-title .el-icon {
  margin-right: 10px;
  font-size: 20px;
}

.notice-content p {
  margin: 10px 0;
  line-height: 1.6;
  color: #666;
}

.exam-selection {
  flex: 1;
  background-color: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.selection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.selection-header h2 {
  margin: 0;
  color: #333;
}

.exam-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.exam-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 6px;
  transition: all 0.3s;
}

.exam-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.exam-info h3 {
  margin: 0 0 10px 0;
  color: #333;
}

.exam-meta {
  display: flex;
  gap: 15px;
  color: #666;
  font-size: 14px;
}

.exam-meta span {
  display: flex;
  align-items: center;
}

@media (max-width: 768px) {
  .exam-main {
    flex-direction: column;
  }
  
  .exam-notice {
    flex: 0 0 auto;
    margin-bottom: 20px;
  }
  
  .exam-meta {
    flex-direction: column;
    gap: 5px;
  }
}
</style>